package com.zhoukx.factory.simplefactory.pizzastore.order;

import com.zhoukx.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.zhoukx.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.zhoukx.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @ClassName OrderPizza
 * @Description: 订购披萨
 * @Author zhoukx
 * @Date 2020/8/6
 **/
public class OrderPizza {

//    public OrderPizza() {
////       Pizza pizza = null;
////       String orderType;// 订购披萨类型
////       do{
////           orderType =gettype();
////           if (orderType.equals("greek")) {
////               pizza = new GreekPizza();
////           }else  if (orderType.equals("cheese")){
////               pizza = new CheesePizza();
////           }else {
////               break;
////           }
////           // 输出披萨的 的制作过程
////           pizza.prepare();
////           pizza.bake();
////           pizza.cut();
////           pizza.box();
////       }while (true);
//    }

    //定义一个简单工厂对象
    SimpleFactory simpleFactory;

    Pizza pizza = null;

    public OrderPizza(SimpleFactory simpleFactory) {
        setFactory(simpleFactory);
    }

    public void setFactory(SimpleFactory simpleFactory) {
        String orderType = "";
        this.simpleFactory = simpleFactory; //  设置工厂对象
        do {
            orderType = gettype();
             pizza = this.simpleFactory.createPizza(orderType);
            //输出pizza
            if (pizza != null) { // 订购成功
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购披萨失败");
                break;
            }
        } while (true);
    }

    // 写一个方法 动态获取客户希望订购的披萨种类
    private String gettype() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
